import { MenuApi } from "@/enums/apiEnum";
import { Routers } from "@/router";
import { defHttp } from "@/utils/http/axios";
import qs from "qs";
import { MenuModel } from './model/menuModel'

export function buildMenus() {
  return defHttp.get<Routers[]>({ url: MenuApi.BuildMenus });
}

export function getMenuTree() {
  return defHttp.get({ url: MenuApi.MenuTree });
}

export function getMenuListByPage() {
  return defHttp.get({ url: MenuApi.GetMenuListByPage })
}

export function getMenuListByPid(pid: number | string) {
  return defHttp.get({ url: MenuApi.RestMenuApi + `/${pid}` })
}

export function saveOrUpdateMenu(menu: MenuModel) {
  return defHttp.post({ url: MenuApi.RestMenuApi, data: menu })
}

export function deleteMenuById(id: number) {
  return defHttp.delete({
    url: MenuApi.RestMenuApi, params: '?' + qs.stringify({ id: id }),
  })
}
